package com.polaris.live.adapter

import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.TimeUtils
import com.bumptech.glide.Glide
import com.polaris.live.R
import com.polaris.live.common.R.color
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.databinding.AdapterLikeBinding
import com.polaris.live.resp.back_resp.UserLikesVo
import com.polaris.live.utils.image.ImageUtils
import com.polaris.live.utils.image.normal
import com.polaris.live.widget.avatar.FrameImageUtils

/**
 * 喜欢列表
 *
 * @author Created by 长空 on 2023/11/2/004 21:00
 */
class LikeAdapter : BaseBindingAdapter<AdapterLikeBinding, UserLikesVo>() {

    private var likeDate: Long = 0L

    init {
        addChildClickViewIds(R.id.iv_avatar)
    }

    override fun convert(holder: VBViewHolder<AdapterLikeBinding>, item: UserLikesVo) {
        holder.vb.apply {
            avFv.setFrameImage(FrameImageUtils.urlToFrameImageBean(item.userBasic.avatarFrame))
            Glide.with(context).load(ImageUtils.imgPathSmall(item.userBasic.avatar)).normal().into(ivAvatar)
            tvName.text = item.userBasic.nickname
            vipView.setVipLevel(item.userBasic.vipLevel)
            viewCountry.setCountry(item.userBasic.country)
            lvLanguage.setLanguage(item.userBasic.language)
            levelView.setRichCharmBySexLevel(item.userBasic.sex, item.userBasic.richs, item.userBasic.charms)
            tvTime.text = TimeUtils.millis2String(item.createTime, "HH:mm")
            tvDate.text = TimeUtils.millis2String(item.createTime, "yyyy-MM-dd")
            if (likeDate >= item.createTime) {
                tvTime.setTextColor(ColorUtils.getColor(color.color_a7a8ad))
                tvDate.setTextColor(ColorUtils.getColor(color.color_a7a8ad))
            } else {
                tvTime.setTextColor(ColorUtils.getColor(color.color_57575C))
                tvDate.setTextColor(ColorUtils.getColor(color.color_57575C))
            }
        }
    }

    fun setLikeDate(likeDate: Long) {
        this.likeDate = likeDate
    }

}